<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>组合商品</title>
		<link rel="stylesheet" href="__PEAR__/component/pear/css/pear.css" />
		<style>
		.layui-input{width:130px;}
		.layui-form-label{width:auto;}
		.layui-form-item .layui-input-inline{width: 130px;}
		</style>
	</head>
	<body class="pear-container">
		<div class="layui-card">
			<div class="layui-card-body">
				<form class="layui-form" action="">
					<div class="layui-form-item">
						<div class="layui-form-item layui-inline">
							<label class="layui-form-label">商品货号</label>
							<div class="layui-input-inline">
								<input type="text" name="item_no" placeholder="" class="layui-input">
							</div>
						</div>
						
						<div class="layui-form-item layui-inline">
							<button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="comblist-query">
								<i class="layui-icon layui-icon-search"></i>
								查询
							</button>
							<button type="reset" class="pear-btn pear-btn-md">
								<i class="layui-icon layui-icon-refresh"></i>
								重置
							</button>
						</div>
					</div>
				</form>
			</div>
		</div>
		<div class="layui-card">
			<div class="layui-card-body">
				<table id="comblist-table" lay-filter="comblist-table"></table>
			</div>
		</div>

		<script type="text/html" id="comblist-toolbar">
			<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
		        <i class="layui-icon layui-icon-add-1"></i>
		        新增
		    </button>
		    <button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">
		        <i class="layui-icon layui-icon-delete"></i>
		        删除
		    </button>
		</script>

		<script type="text/html" id="comblist-bar">
			<button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit"><i class="layui-icon layui-icon-edit"></i></button>
		    <button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove"><i class="layui-icon layui-icon-delete"></i></button>
		</script>

		<script type="text/html" id="comblist-enable">
			<input type="checkbox" name="enable" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="user-enable" checked = "{{ d.enable == 0 ? 'true' : 'false' }}">
		</script>

		<script type="text/html" id="comblist-createTime">
			{{layui.util.toDateString(d.createTime, 'yyyy-MM-dd')}}
		</script>

		<script src="__STATIC__/lib/layui/layui.js"></script>
		<script src="__PEAR__/component/pear/pear.js"></script>
		<script>
			layui.use(['table', 'form', 'jquery','common'], function() {
				let table = layui.table;
				let form = layui.form;
				let $ = layui.jquery;
				let common = layui.common;

				let MODULE_PATH = "/{$MODULE_NAME}/Product/";

				let cols = [
					[
						{
							title: '商品货号',
							field: 'item_no',
							align: 'center',
							width: 100
						},
						{
							title: '商品名称',
							field: 'item_name',
							align: 'center'
						},
						{
							title: '自编码',
							field: 'item_subno',
							align: 'center'
						},
						{
							title: '商品类型',
							field: 'combine_sta',
							align: 'center'
						},
						{
							title: '类别编码',
							field: 'item_clsno',
							align: 'center'
						},
						{
							title: '类别名称',
							field: 'cls_name',
							align: 'center'
						},
						{
							title: '规格',
							field: 'item_size',
							align: 'center'
						},
						{
							title: '单位',
							field: 'unit_no',
							align: 'center'
						},
						{
							title: '操作',
							toolbar: '#comblist-bar',
							align: 'center',
							width: 130
						}
					]
				]

				table.render({
					elem: '#comblist-table',
					url: MODULE_PATH+"searchcomb",
					page: true,
					cols: cols,
					skin: 'line',
					toolbar: '',
					defaultToolbar: []
				});

				table.on('tool(comblist-table)', function(obj) {
					if (obj.event === 'remove') {
						window.remove(obj);
					} else if (obj.event === 'edit') {
						window.edit(obj);
					}
				});

				table.on('toolbar(comblist-table)', function(obj) {
					if (obj.event === 'add') {
						window.add();
					} else if (obj.event === 'refresh') {
						window.refresh();
					} else if (obj.event === 'batchRemove') {
						window.batchRemove(obj);
					}
				});

				form.on('submit(comblist-query)', function(data) {
					table.reload('comblist-table', {
						where: data.field,
						page:{curr:1}
					})
					return false;
				});

				form.on('switch(comblist-enable)', function(obj) {
					layer.tips(this.value + ' ' + this.name + '：' + obj.elem.checked, obj.othis);
				});

				window.edit = function(obj) {
					var item_no=obj.data.item_no;
					window.location.href=MODULE_PATH + 'comdetail/item_no/'+item_no+'.html';
				}

				window.refresh = function(param) {
					table.reload('comblist-table');
				}
			})
		</script>
	</body>
</html>
